#include "wakeupchannel.h"
#include "tinyrpc/net/event.h"
#include <sys/eventfd.h>
#include <unistd.h>
#include "tinyrpc/base/logger/logger.h"
#include "../eventloop.h"
namespace TinyRPC{


WakeupChannel::WakeupChannel()
: AbstractChannel(eventfd(0,EFD_CLOEXEC|EFD_NONBLOCK))

{
    // m_event->enableReading();
    // m_event->setReadTask();
    //updateEvent(ReadEvent, Task(std::bind(&WakeupChannel::read, this), false), m_ownerLoop);
}

void WakeupChannel::wakeupUpdateEvent(EventLoop * loop){
    m_ownerLoop = loop;
    updateEvent(ReadEvent, Task(std::bind(&WakeupChannel::read, this), false), m_ownerLoop);
}
void WakeupChannel::read(){
    uint64_t buf;
    // 读取出非0值， 将其重新设置为0
    int rc = ::read(m_fd, &buf, sizeof(uint64_t));
}
void WakeupChannel::write(){
    // 这里需要写入一个非0值
    uint64_t buf = 1;
    int rt = ::write(m_fd, &buf, sizeof(uint64_t));
    if(rt < 0){
        LOG_ERROR<<"wakefdChannel write error";
    }
}

}
